﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;

namespace ServerMonitor.Common
{
    public class LogHelper
    {  
        public static void WriteLog(string msg,string mobile)
        {
            try
            {
                 

                string fileName = DateTime.Now.ToString("yyyyMMdd") + ".Log";
                if (Directory.Exists(Application.StartupPath+"/log/") == false)//如果不存
                {
                    Directory.CreateDirectory(Application.StartupPath + "/log/");
                }
                if (!File.Exists(Application.StartupPath + "/log/" + fileName))
                {  
                    //不存在文件 
                    File.Create(Application.StartupPath + "/log/" + fileName);//创建该文件  
                }

                System.IO.StreamWriter sw = System.IO.File.AppendText(Application.StartupPath + "/log/" + fileName);
                sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + mobile + "-->" + msg);
                sw.Close();
            }
            catch
            { }
        }

        /// <summary>
        /// 写入操作日志
        /// </summary>
        /// <param name="msg"></param>
        public static void Log(string msg)
        {
            try
            {


                string fileName = DateTime.Now.ToString("yyyyMMdd") + "_Oper.Log";
                if (Directory.Exists(Application.StartupPath + "/log/") == false)//如果不存
                {
                    Directory.CreateDirectory(Application.StartupPath + "/log/");
                }
                if (!File.Exists(Application.StartupPath + "/log/" + fileName))
                {
                    //不存在文件 
                    File.Create(Application.StartupPath + "/log/" + fileName);//创建该文件  
                }

                System.IO.StreamWriter sw = System.IO.File.AppendText(Application.StartupPath + "/log/" + fileName);
                sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")  + "--->" + msg);
                sw.Close();
            }
            catch
            { }
        }

       
    }
}
